package com.example.springboot.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.common.Result;
import com.example.springboot.entity.Articles;
import com.example.springboot.entity.Categories;
import com.example.springboot.service.IArticlesService;
import com.example.springboot.service.ICategoriesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * <p>
 * 分类表 API控制器 - 不需要token验证的API
 * </p>
 *
 * @author
 */
@RestController
@RequestMapping("/api/categories")
public class CategoriesApi {

    @Resource
    private ICategoriesService categoriesService;

    //查询分类
    @GetMapping("/list")
    public Result list() {
        return Result.success(categoriesService.list());
    }



    @GetMapping("/{id}")
    public Result getByCategoryId(@PathVariable Integer id) {
        QueryWrapper<Categories> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        return Result.success(categoriesService.list(queryWrapper));
    }
}
